#ifndef STATEFULSPRITE_H
#define STATEFULSPRITE_H

#include <string>
#include <vector>
#include <map>
#include <utility>
#include "AnimatedSprite.h"
#include "PenjinTypes.h"
#include "CollisionFlags.h"
#include "CollisionRegion.h"

using namespace std;

class StatefulSprite
{
    public:
        StatefulSprite();
        StatefulSprite(string filename);
        ~StatefulSprite();

        void load(string filename);
        void addSpriteState(string state, SDL_Surface *surface, uint sheetWidth, uint sheetHeight, uint startIndex, uint numFrames, uint frameRate, uint transparentColour, bool looping=true);
        AnimatedSprite *getSpriteForState(string state);
        CollisionRegion *getCollisionForState(string state);
        void setSpriteState(string state) {m_currentState = state;}
        string getSpriteState() const {return m_currentState;}
        void playSound(string sound);
        void playFrameSound(string state, uint frameIndex);
        void playFrameSound(uint frameIndex);
        vector< vector<string> > getEvents(string eventName);
        vector< vector<string> > getFrameEvents(string stateName, uint frameNumber);
    	CollisionFlags m_collisionFlags;
    protected:
    	void init();
        //PENJIN_ERRORS setTransparentColour(SDL_Surface *image, const Vector2di& v);
        //PENJIN_ERRORS setTransparentColour(SDL_Surface *image, const Colour& c);
    private:

        string m_currentState;
        string m_filename;
    	vector<AnimatedSprite *> m_sprites;
    	vector<CollisionRegion *> m_collisionRegions;
    	vector<string> m_spriteStates;
    	// multimap< event, vector<parameter> > m_events
    	// parameters can be different things - target, action, etc.
    	multimap< string, vector<string> > m_events;
    	// multimap< pair<state, framenumber>, vector<parameter> > m_frameEvents
    	multimap< pair<string, uint>, vector<string> > m_frameEvents;
    	// map<pair<state, framenumber>, soundname> m _frameSounds
    	map<pair<string, uint>, string> m_frameSounds;
};

#endif // STATEFULSPRITE_H
